package com.fc.test.service;

import java.util.List;
import java.util.Arrays;

import com.fc.test.mapper.auto.TsysUserMapper;
import com.fc.test.model.auto.MemberIncome;
import com.fc.test.model.auto.TsysUser;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.MemberJhMapper;
import com.fc.test.model.auto.MemberJh;
import com.fc.test.model.auto.MemberJhExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;
import org.springframework.stereotype.Service;


@Service
public class MemberJhService implements BaseService<MemberJh, MemberJhExample>{
	@Autowired
	private MemberJhMapper memberJhMapper;
	@Autowired
	private TsysUserMapper tsysUserMapper;
      	   	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<MemberJh> list(Tablepar tablepar,String name){
	        MemberJhExample testExample=new MemberJhExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andLxLike("%"+name+"%");
	        }
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<MemberJh> list= memberJhMapper.selectByExample(testExample);
		 for (MemberJh l: list) {

			 TsysUser u  = tsysUserMapper.selectByPrimaryKey(l.getUid());
			 l.setuName(u.getNickname());
		 }
	        PageInfo<MemberJh> pageInfo = new PageInfo<MemberJh>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			MemberJhExample example=new MemberJhExample();
			example.createCriteria().andIdIn(lista);
			return memberJhMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public MemberJh selectByPrimaryKey(String id) {
				
			return memberJhMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(MemberJh record) {
		return memberJhMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(MemberJh record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return memberJhMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(MemberJh record, MemberJhExample example) {
		
		return memberJhMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(MemberJh record, MemberJhExample example) {
		
		return memberJhMapper.updateByExample(record, example);
	}

	@Override
	public List<MemberJh> selectByExample(MemberJhExample example) {
		
		return memberJhMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(MemberJhExample example) {
		
		return memberJhMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(MemberJhExample example) {
		
		return memberJhMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param memberJh
	 * @return
	 */
	public int checkNameUnique(MemberJh memberJh){
		MemberJhExample example=new MemberJhExample();
		example.createCriteria().andLxEqualTo(memberJh.getLx());
		List<MemberJh> list=memberJhMapper.selectByExample(example);
		return list.size();
	}


}
